/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package services;

import Entitys.Factura;
import java.util.Date;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;


/**
 *
 * @author MAURO
 */
public class FacturaServices {
    EntityManagerFactory emf= Persistence.createEntityManagerFactory("DrugStoreProPU");
         EntityManager em=emf.createEntityManager();
         
         public void create (Factura f){
          em.getTransaction().begin();
          em.persist(f);
          em.getTransaction().commit();
          em.close();
         }
    
         public void delete (Integer  p){
          em.getTransaction().begin();
          Factura p1=em.find(Factura.class, p);
          if(p1!= null)
          em.remove(p1);
          em.getTransaction().commit();
          em.close();
         }
          public List<Factura> readAll(){
         Query q=em.createNamedQuery("Factura.findAll");
         return q.getResultList();
         }
          
          public List<Factura>  readFacturesToday(Date d){
             Query q= em.createQuery("SELECT f FROM Factura f WHERE f.fecha=:fechahoy");
             q.setParameter("fechahoy", d);
             return q.getResultList();
          }
    
}
